package com.qf.commo.utils;

import java.util.HashMap;

public class R extends HashMap<String,Object> {
    public R(){
        //code 为0代表成功,非0代表失败
        super.put("code",0);
        super.put("msg","success");
    }
    //响应成功
    public  static  R ok(){
        return new R();
    }
    //根据操作数据库结果返回数据
    public  static  R out(Object flag){
        if (flag instanceof Boolean)
        {
            if ((Boolean) flag){
                return R.ok();
            }else
            {
                return R.error();
            }
        }else if (flag instanceof Integer){
            if ((Integer)flag>0){
                return R.ok();
            }else {
                return R.error();
            }
        }
        return R.error();
    }
    //响应成功带有提示信息
    public  static  R ok(String msg){
        R r = new R();
        r.put("msg",msg);
        return r;
    }
    public static R error(String msg){
        R r = new R();
        r.put("code",500);
        r.put("msg",msg);
        return  r;
    }
    public static R error(){
        R r = new R();
        r.put("code",500);
        r.put("msg","error");
        return  r;
    }
    public static R putDate(String key,Object value){
        R r = new R();
        r.put(key,value);
        return r;
    }
}
